Operating System
Complete Learning Roadmap: From Fundamentals to Building Your Own OS
Prerequisites
Programming Skills
C Programming (Essential)
- Pointers & pointer arithmetic
- Dynamic memory: malloc, calloc, realloc, free
- Structures, unions, typedef
- Bitwise operations
- File I/O operations
- Function pointers & callbacks
- Preprocessor directives & macros
C++ Programming
- OOP: Classes, inheritance, polymorphism
- Templates & STL containers
- Smart pointers, RAII
- Exception handling
Assembly Language (x86/x64)
- CPU registers: General, segment, control
- Instruction set architecture
- Stack operations: push, pop, call, ret
- Calling conventions
- Interrupt handling
- Inline assembly in C
Computer Architecture
- Von Neumann vs Harvard architecture
- CPU components: ALU, Control Unit, Registers
- Instruction cycle: Fetch, Decode, Execute
- Pipeline architecture & hazards
- Memory hierarchy: Registers → L1/L2/L3 Cache → RAM → Storage
- Cache coherence protocols (MESI)
- Virtual memory hardware (MMU, TLB)
- I/O buses: PCI, PCIe, USB, SATA
- Interrupt controllers: PIC, APIC
- DMA controllers
- Privilege levels (Ring 0-3)
Data Structures
- Linear: Arrays, Linked Lists (single, double, circular), Stacks, Queues, Deques
- Trees: Binary Trees, BST, AVL, Red-Black, B-Trees, B+ Trees
- Hash Tables: Collision handling (chaining, open addressing)
- Heaps: Min-heap, Max-heap, Priority Queues
- Graphs: Representations, BFS, DFS, Shortest paths
Learning Path (5 Phases)
Phase 1: Foundation (4-6 weeks)
- Master C programming with pointers & memory
- Learn basic x86 Assembly
- Study computer architecture
- Review data structures
- Read OS introduction chapters
Phase 2: Core Concepts (6-8 weeks)
- Process & Thread management
- CPU scheduling algorithms
- Synchronization primitives
- Classic synchronization problems
- Deadlock handling strategies
Phase 3: Advanced Topics (6-8 weeks)
- Virtual memory & paging
- Page replacement algorithms
- File system design & implementation
- I/O systems & device drivers
- Security & protection mechanisms
Phase 4: OS Development (8-12 weeks)
- Set up cross-compilation environment
- Write bootloader
- Implement kernel with interrupts
- Add memory management (paging)
- Implement process scheduler
- Write device drivers
- Create file system
Phase 5: Specialization (Ongoing)
- Linux kernel module development
- Real-time OS design
- Container & virtualization internals
- Security hardening
- Contributing to open-source OS
Unit 1: Introduction to Operating Systems
1.1 Fundamentals
- Definition & purpose of Operating System
- Computer system organization
- History & Evolution:
- Serial Processing (no OS)
- Simple Batch Systems
- Multiprogrammed Batch
- Time-Sharing Systems
- Modern Desktop/Server OS
1.2 OS Functions & Services
- Process management: Creation, scheduling, termination
- Memory management: Allocation, protection, virtual memory
- File system management: Organization, access control
- I/O system management: Device drivers, buffering
- Secondary storage management: Disk scheduling
- Networking & communication services
- Protection & security services
- Command interpreter (Shell)
- GUI & user interface
1.3 Types of Operating Systems
- Batch OS: Jobs processed in batches, spooling
- Multiprogramming: Multiple jobs in memory
- Time-sharing: CPU time slicing, interactive
- Real-Time:
- Hard RT: Strict deadlines (pacemakers, ABS)
- Soft RT: Best effort (multimedia)
- Distributed: Multiple computers, transparency
- Embedded: Dedicated function, resource-constrained
- Mobile: Touch interface, power management
- Network OS: File/print sharing
1.4 OS Structures
- Simple/Monolithic: No clear structure (MS-DOS)
- Layered: Each layer uses lower layer services
- Hardware → Kernel → System Programs → Applications
- Microkernel: Minimal kernel, services in user space
- Examples: Minix, QNX, L4
- Benefits: Reliability, security
- Drawback: Performance overhead
- Modular: Loadable kernel modules (Linux)
- Hybrid: Combination (Windows NT, macOS)
- Exokernel: Library OS, app-level resource management
1.5 System Calls
- Interface between user programs & OS kernel
- Parameter passing: Registers, Block/table, Stack
- Process Control: fork(), exec(), exit(), wait(), abort()
- File Management: open(), read(), write(), close(), seek()
- Device Management: ioctl(), read(), write()
- Information: getpid(), alarm(), sleep(), time()
- Communication: pipe(), shmget(), msgget(), socket()
- Protection: chmod(), chown(), umask()
1.6 Operating Modes
- User mode vs Kernel mode
- Mode bit in processor status register
- Privileged instructions (only in kernel mode)
- Protection rings (Ring 0-3)
- System call mechanism: Trap/software interrupt
- Context switch during mode transition
Unit 2: Process Management
2.1 Process Concept
- Process vs Program (active vs passive)
- Process memory layout:
- Text: Code
- Data: Global variables
- Heap: Dynamic memory
- Stack: Local variables, function calls
- Process states: New → Ready → Running → Waiting → Terminated
- State transition diagram
2.2 Process Control Block (PCB)
- Process ID (PID) & Parent PID
- Process state
- Program counter
- CPU registers (saved during context switch)
- CPU scheduling info: Priority, pointers
- Memory management info: Base/limit, page tables
- Accounting info: CPU time used
- I/O status: Open files, devices
2.3 Process Operations
- Creation:
- fork(): Create child process (copy parent)
- vfork(): Share parent's memory
- clone(): Fine-grained sharing (Linux)
- CreateProcess() (Windows)
- Parent-child relationships & process tree
- Termination:
- exit(): Normal termination
- abort(): Abnormal termination
- Zombie: Terminated but not reaped
- Orphan: Parent terminated first
2.4 Context Switching
- Save state of current process (registers, PC)
- Load state of next process
- Overhead factors: Register count, memory maps
- Hardware support (multiple register sets)
2.5 Threads
- Lightweight processes within a process
- Thread components: Thread ID, PC, Registers, Stack
- Shared: Code, Data, Files
- Benefits:
- Responsiveness
- Resource sharing
- Economy (faster creation/switching)
- Scalability (multiprocessor)
2.6 Multithreading Models
- User-level threads: Thread library in user space, fast but no parallelism
- Kernel-level threads: OS managed, true parallelism
- Many-to-One: Multiple user threads → one kernel thread
- One-to-One: Each user thread → kernel thread (Linux, Windows)
- Many-to-Many: User threads multiplexed to kernel threads
2.7 Thread Libraries
- POSIX Pthreads: pthread_create(), pthread_join()
- Windows threads
- Java threads: Thread class, Runnable interface
- Thread pools
- Thread-local storage
2.8 Inter-Process Communication
- Shared Memory: shmget(), shmat(), shmdt(), shmctl()
- Message Passing: send(), receive() - Direct/Indirect
- Pipes:
- Anonymous: Parent-child only
- Named (FIFOs): Any processes
- Message Queues: msgget(), msgsnd(), msgrcv()
- Sockets: Network & local communication
- Signals: Asynchronous notification (SIGINT, SIGKILL)
Unit 3: CPU Scheduling
3.1 Basic Concepts
- CPU-I/O Burst Cycle
- CPU Scheduler: Selects from ready queue
- Dispatcher: Context switch, mode switch, jump to user program
- Dispatch latency
3.2 Scheduling Criteria
- CPU Utilization: % time CPU busy (40-90%)
- Throughput: Processes completed per time unit
- Turnaround Time: Submission to completion
- Waiting Time: Time in ready queue
- Response Time: Submission to first response
3.3 Scheduling Types
- Preemptive: OS can interrupt running process
- Non-preemptive: Process runs until completion/block
- Cooperative: Process voluntarily yields
3.4 Scheduling Algorithms
- FCFS: First-Come-First-Served
- Simple but convoy effect
- SJF: Shortest Job First
- Optimal average waiting time
- Requires burst time prediction
- SRTF: Shortest Remaining Time First (preemptive SJF)
- Priority: Based on priority values
- Problem: Starvation
- Solution: Aging
- Round Robin: Time quantum
- Fair, good response time
- Context switch overhead
- Multilevel Queue: Separate queues with different algorithms
- Multilevel Feedback Queue: Processes move between queues
- HRRN: Highest Response Ratio Next
- Lottery: Probabilistic with tickets
- Fair Share: Per-user/group allocation
3.5 Real-Time Scheduling
- Rate Monotonic (RM): Static priority = 1/period
- Earliest Deadline First (EDF): Dynamic priority
- Proportional Share: CPU shares
- Priority inversion problem
- Priority inheritance protocol
3.6 Multiprocessor Scheduling
- Asymmetric vs Symmetric multiprocessing
- Processor affinity: Soft & Hard
- Load balancing: Push & Pull migration
- NUMA-aware scheduling
Unit 4: Process Synchronization
4.1 Background
- Concurrent vs Parallel execution
- Race conditions
- Critical section problem
- Requirements: Mutual Exclusion, Progress, Bounded Waiting
4.2 Software Solutions
- Peterson's Algorithm: Two-process solution using flag[] and turn
- Dekker's Algorithm: First correct solution
- Lamport's Bakery: N-process solution with ticket numbers
- Filter Algorithm: N-process generalization
4.3 Hardware Solutions
- Interrupt Disabling: Uniprocessor only
- Test-and-Set (TAS): Atomic read-modify-write
- Compare-and-Swap (CAS): Conditional update
- Fetch-and-Add: Atomic increment
- Memory barriers/fences
4.4 Synchronization Primitives
- Mutex: acquire(), release()
- Spinlocks: Busy-waiting locks
- Semaphores:
- Counting: Resource management
- Binary: Mutex alternative
- Operations: wait()/P(), signal()/V()
- Monitors: High-level abstraction
- Condition Variables: wait(), signal(), broadcast()
- Read-Write Locks: Multiple readers OR single writer
4.5 Classic Problems
- Producer-Consumer: Bounded buffer
- Full & empty semaphores + mutex
- Readers-Writers:
- First: Readers priority
- Second: Writers priority
- Third: Fair
- Dining Philosophers:
- 5 philosophers, 5 forks
- Solutions: Asymmetric, Chandy-Misra
- Sleeping Barber
- Cigarette Smokers
4.6 Advanced Topics
- Livelock
- Priority inversion
- Lock-free data structures
- Transactional memory
Unit 5: Deadlocks
5.1 Characterization
- Definition: Circular wait for resources
- Necessary Conditions:
- Mutual Exclusion: One process at a time
- Hold and Wait: Hold one, request another
- No Preemption: Cannot forcibly take resources
- Circular Wait: Cycle in wait graph
5.2 Resource Allocation Graph
- Vertices: Processes (circles), Resources (rectangles)
- Request edge: Process → Resource
- Assignment edge: Resource → Process
- Cycle = potential deadlock (guaranteed if single instance)
5.3 Handling Methods
- Prevention: Negate necessary conditions
- Avoidance: Don't enter unsafe states
- Detection & Recovery: Allow and recover
- Ignorance: Ostrich algorithm (most OS)
5.4 Deadlock Prevention
- Eliminate Hold-and-Wait: Request all resources at once
- Allow Preemption: Release held resources
- Eliminate Circular Wait: Resource ordering
5.5 Banker's Algorithm
- Data structures:
- Available[m]: Available resources
- Max[n][m]: Maximum demand
- Allocation[n][m]: Currently allocated
- Need[n][m] = Max - Allocation
- Safety Algorithm: Find safe sequence
- Resource-Request Algorithm: Grant if safe
5.6 Detection & Recovery
- Detection: Wait-for graph, matrix algorithm
- Recovery:
- Process termination: All or one-by-one
- Resource preemption: Select victim, rollback
Unit 6: Memory Management
6.1 Basics
- Address Binding: Compile-time, Load-time, Execution-time
- Logical (virtual) vs Physical address
- MMU: Memory Management Unit
- Relocation register
6.2 Contiguous Allocation
- Fixed Partitioning: Equal or unequal sizes
- Variable Partitioning: Dynamic allocation
- Allocation Algorithms:
- First Fit: First sufficient hole
- Best Fit: Smallest sufficient hole
- Worst Fit: Largest hole
- Next Fit: Continue from last
6.3 Fragmentation
- External: Free memory in non-contiguous blocks
- Internal: Allocated > needed
- Compaction: Relocate processes
6.4 Paging
- Physical memory divided into frames
- Logical memory divided into pages
- Page table: Page → Frame mapping
- Address translation: Page number + offset
- Page table entry: Frame number, valid bit, protection bits, dirty bit
- TLB: Translation Lookaside Buffer
- Associative memory for fast lookup
- Hit ratio affects performance
- Effective Access Time (EAT)
6.5 Page Table Structures
- Hierarchical/Multilevel: Two-level, three-level
- Hashed page tables: Large address spaces
- Inverted page tables: One entry per frame
6.6 Segmentation
- User view: Meaningful units (code, data, stack)
- Segment table: Base + limit
- Segmentation with paging (Intel x86)
6.7 Virtual Memory
- Larger logical than physical address space
- Demand Paging:
- Load pages only when needed
- Valid-invalid bit in page table
- Page fault handling steps
- Copy-on-Write: Efficient fork()
6.8 Page Replacement Algorithms
- FIFO: First loaded, first replaced (Belady's anomaly)
- Optimal: Replace page used farthest in future
- LRU: Least Recently Used
- Counter implementation
- Stack implementation
- LRU Approximation:
- Reference bit
- Second-chance (Clock)
- Enhanced second-chance
- LFU: Least Frequently Used
- MFU: Most Frequently Used
6.9 Frame Allocation
- Minimum frames needed
- Equal vs Proportional allocation
- Global vs Local replacement
6.10 Thrashing
- High paging activity, low CPU utilization
- Working Set Model: Pages in use
- Page-Fault Frequency control
6.11 Kernel Memory
- Buddy System: Power-of-2 blocks
- Slab Allocator: Object caching
Unit 7: File Systems
7.1 File Concept
- Types: Regular, Directory, Special, Links
- Attributes: Name, Type, Location, Size, Protection, Time
- Operations: Create, Open, Read, Write, Seek, Close, Delete
- File locking: Shared vs Exclusive
7.2 Access Methods
- Sequential: Read/write in order
- Direct/Random: Access any position
- Indexed: Using index structure
7.3 Directory Structure
- Single-level: All files in one directory
- Two-level: Separate per user
- Tree-structured: Hierarchical
- Acyclic-graph: Shared files (links)
7.4 File System Implementation
- On-disk: Boot block, Superblock, Inodes, Data blocks
- In-memory: Mount table, Directory cache, Open file table
- VFS: Virtual File System abstraction
7.5 Allocation Methods
- Contiguous: Simple, fast, external fragmentation
- Linked: No fragmentation, sequential only
- FAT: File Allocation Table
- Indexed: Index block with pointers
- Combined: Unix inode (direct + indirect)
7.6 Free Space Management
- Bitmap: One bit per block
- Linked list: Free blocks linked
- Grouping: First block stores addresses
- Counting: Start + count pairs
7.7 File System Types
- FAT12/16/32, exFAT
- NTFS: Journaling, security, compression
- ext2/3/4: Linux, journaling (ext3+)
- ZFS: Checksums, RAID, snapshots
- Btrfs: Copy-on-write, snapshots
7.8 Journaling
- Write-ahead logging for crash recovery
- Modes: Data, Ordered, Writeback
Unit 8: I/O Systems
8.1 I/O Hardware
- Device types: Block, Character, Network
- Components: Ports, Buses, Controllers
- Device registers: Data, Status, Control
8.2 I/O Techniques
- Programmed I/O: CPU polling
- Interrupt-driven: Device interrupts CPU
- DMA: Direct Memory Access, CPU-free transfer
8.3 I/O Interface
- Blocking vs Non-blocking I/O
- Synchronous vs Asynchronous
- Buffering: Single, Double, Circular
- Caching, Spooling
8.4 Disk Scheduling
- FCFS: Simple, long seek times
- SSTF: Shortest Seek Time First
- SCAN: Elevator algorithm
- C-SCAN: Circular SCAN
- LOOK/C-LOOK: Only go to last request
8.5 RAID
- RAID 0: Striping (no redundancy)
- RAID 1: Mirroring
- RAID 5: Distributed parity
- RAID 6: Double parity
- RAID 10: Mirrored stripes
8.6 Storage Technologies
- HDD vs SSD (NAND flash)
- NVMe, M.2
- SAN, NAS
Unit 9: Protection & Security
9.1 Protection Goals
- Principle of least privilege
- Defense in depth
- Separation of duties
9.2 Access Control
- Access matrix: Subjects × Objects
- ACLs: Per-object permissions
- Capabilities: Per-subject permissions
- RBAC: Role-Based Access Control
9.3 Security Threats
- CIA Triad: Confidentiality, Integrity, Availability
- Program threats: Trojans, Viruses, Worms, Ransomware
- System threats: DoS, Buffer overflow, Rootkits
9.4 Authentication
- Passwords (hashing, salting)
- Tokens, Smart cards
- Biometrics
- Multi-factor authentication
9.5 Cryptography
- Symmetric: AES, DES, 3DES
- Asymmetric: RSA, ECC
- Hash functions: SHA-256, MD5
- Digital signatures, PKI
9.6 System Hardening
- Secure boot, Trusted boot
- Sandboxing, Virtualization
- ASLR, DEP/NX
- Stack canaries
Unit 10: Distributed & Special-Purpose Systems
10.1 Distributed Systems
- Characteristics: Resource sharing, Transparency, Scalability
- Network OS vs Distributed OS
- Client-Server, Peer-to-Peer
- Middleware: RPC, RMI, CORBA
10.2 Distributed Synchronization
- Clock synchronization (NTP)
- Logical clocks: Lamport, Vector
- Distributed mutual exclusion
- Election algorithms: Bully, Ring
10.3 Distributed File Systems
- NFS, AFS, HDFS
- Consistency models
- Replication and caching
10.4 Real-Time OS
- Hard vs Soft real-time
- Deterministic scheduling
- Examples: VxWorks, FreeRTOS, QNX
10.5 Embedded OS
- Resource constraints
- Examples: Embedded Linux, Zephyr, RIOT
10.6 Mobile OS
- Android: Linux kernel, ART, HAL
- iOS: XNU kernel, Cocoa Touch
- Power management, Sensors
All Algorithms
CPU Scheduling
FCFSSJFSRTFPriorityRound RobinMLQMLFQHRRNLotteryFair ShareRate MonotonicEDFCFSPage Replacement
FIFOOptimalLRUClockSecond ChanceNRULFUMFUWorking SetPFFDisk Scheduling
FCFSSSTFSCANC-SCANLOOKC-LOOKSynchronization
Peterson'sDekker'sBakeryFilterTASCASFAASpinlockMCS LockDeadlock
Banker'sSafetyDetectionWait-DieWound-WaitMemory
First FitBest FitWorst FitNext FitBuddySlabTools & Technologies
Development
GCCClangNASMGASMakeCMakeGDBLLDBValgrindstraceltraceEmulators
QEMUBochsVirtualBoxVMwareKVMHyper-VDockerBootloaders
GRUBLILOUEFILimineMultibootU-BootProfiling
perfftraceeBPFSystemTapDTracehtopvmstatOS Development from Scratch
Step 1: Environment Setup
- Install cross-compiler (i686-elf-gcc or x86_64-elf-gcc)
- Set up QEMU emulator
- Configure Makefile build system
- Initialize Git repository
- Set up GDB remote debugging
Step 2: Bootloader
- BIOS boot process (MBR at sector 0)
- 512-byte boot sector in assembly
- Enable A20 line
- Set up GDT
- Switch Real Mode → Protected Mode → Long Mode
- Load kernel from disk
Step 3: Kernel Foundation
- Kernel entry point (kmain)
- VGA text mode (0xB8000)
- printf/kprintf implementation
- Set up IDT
- Implement ISRs
- Configure PIC
- Timer interrupt (PIT)
- Keyboard interrupt
- Serial debugging
Step 4: Memory Management
- Physical memory detection
- Physical Memory Manager (bitmap/stack)
- Page frame allocator
- Paging structures
- Enable paging (CR0)
- Virtual memory manager
- Kernel heap (malloc/free)
Step 5: Process Management
- Process structure (PCB)
- TSS setup
- Context switch
- Kernel stack per process
- Scheduler (Round Robin)
- User mode transition
- System call interface
- fork(), exec(), exit()
Step 6: Device Drivers
- Keyboard (PS/2)
- Timer (PIT/HPET)
- ATA/AHCI disk
- Framebuffer graphics
Step 7: File System
- VFS abstraction
- Block device interface
- FAT32 or ext2 implementation
- Buffer cache
Step 8: User Space
- ELF loader
- C library port
- Shell implementation
- Basic utilities
Cutting-Edge Developments
🤖 AI-Integrated OS
- ML-based resource management
- Intelligent scheduling
- Self-healing systems
- Proactive threat detection
- Smart power management
☁️ Cloud & Edge
- Container orchestration (K8s)
- Serverless computing
- Edge computing
- Unikernels
- Microservices
🔐 Advanced Security
- TPM, SGX, TrustZone
- Secure enclaves
- Zero-trust
- Confidential computing
- Post-quantum crypto
📡 IoT & Embedded
- Zephyr, RIOT
- Ultra-low-power
- Edge AI
- OTA updates
⚛️ Emerging Tech
- Quantum OS research
- Rust-based OS (Redox)
- Capability-based (seL4)
- Green computing
Project Ideas
Beginner
- CPU Scheduling Simulator with Gantt charts
- Page Replacement Visualizer
- Disk Scheduling Simulator
- Banker's Algorithm Implementation
- Producer-Consumer Problem
- Simple Unix Shell
Intermediate
- Custom Shell with piping & redirection
- Thread Pool Library
- Custom malloc/free
- In-memory File System
- Process Monitor (htop clone)
- System Call Tracer
Advanced
- Bootloader from scratch
- Minimal kernel with interrupts
- Paging & virtual memory
- Preemptive multitasking kernel
- Simple file system
- Device drivers
- Complete hobby OS
Expert
- Linux Kernel Module
- Container Runtime
- Type-1/2 Hypervisor
- RTOS for embedded
- ML-based Scheduler
Resources
Books
- Operating System Concepts - Silberschatz
- Modern Operating Systems - Tanenbaum
- OS: Three Easy Pieces - Arpaci-Dusseau (FREE)
- Linux Kernel Development - Robert Love
- Understanding the Linux Kernel - Bovet
Online
- OSDev Wiki: wiki.osdev.org
- xv6 (MIT) teaching OS
- Linux From Scratch
- os.phil-opp.com (Rust OS)
- littleosbook.github.io
Courses
- MIT 6.828: OS Engineering
- Berkeley CS 162
- Georgia Tech CS 6200 (Udacity)
- Stanford CS 140